<script setup lang="ts">
import MindMap from '@/components/mind-map/Index.vue'
import useCourseStore from '@/stores/course'
import { storeToRefs } from 'pinia'
import { computed, ref } from 'vue'
import { summaryToMind } from '@/views/course-analysis/components/mind-helper'
const props = defineProps({
  mKey: {
    type: String,
    default: 'mm_key'
  },
})
const emits = defineEmits(['onReady'])
const courseStore = useCourseStore()
const { summarization } = storeToRefs(courseStore)

const mindMapData = computed(() => {
  const { MindMapSummary } = summarization.value
  if (!MindMapSummary.length) return []
  const data = MindMapSummary.map((item: any) => {
    return summaryToMind(item, true)
  })
  const jsonObject: any | null = data[0] ? data[0] : null
  emits('onReady', jsonObject)
  return jsonObject
})

const mindMap = ref(null)

const handleExport = (value: any) => {
  if (mindMap.value) {
    mindMap.value.handleExport(value)
  }
}

defineExpose({
  handleExport
})

</script>

<template>
  <mind-map ref="mindMap" :key="props.mKey" :map-key="props.mKey" :data="mindMapData" readonly need-left/>
</template>

<style scoped lang="scss">

</style>